export class HealCreepFlagTask implements ICreepTask{
  run(creep: Creep): void {

    if (creep.hits < creep.hitsMax * 0.9 && creep.body.some(part => part.type === HEAL)) {
      creep.heal(creep);
    }

    if(!creep.memory.flagNameTarget){
      return;
    }

    const flag = Game.flags[creep.memory.flagNameTarget];

    if(flag){
      const range = 3;
      if(!creep.pos.inRangeTo(flag,range)){
        creep.go(flag);
      }

      // 附近是否有需要治疗的Creep
      let target:any | null = null;
      const healCreeps = creep.pos.findInRange(FIND_MY_CREEPS,10)
        .filter((c) => c.hits < c.hitsMax * 0.9);
      if(healCreeps.length > 0){
        target = healCreeps[0];
      }
      if(creep.heal(target) === ERR_NOT_IN_RANGE){
        creep.go(target);
      }
      
    }
  }
}